package com.wenbing.miio.util;

import java.util.Objects;

/**
 * @author wen bing
 * @projectName: miio
 * @package: com.wenbing.miio.util
 * @className: ClassUtils
 * @date 2024/09/24 17:10
 **/
public class ClassUtils {

    /**
     * 获取类的SimpleName
     * @param clazz
     * @return
     */
    public static String simpleName(Class clazz) {
        String name = clazz.getSimpleName();
        if (name == null || name.isEmpty()) {
            name = clazz.getName();
            name = name.substring(name.lastIndexOf(".") + 1);
        }
        return name;
    }

    /**
     * 获取类的SimpleName
     * @param o
     * @return
     */
    public static String simpleName(Object o) {
        if (Objects.isNull(o)) {
            return null;
        }
        return simpleName(o.getClass());
    }
}
